﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using STLGROUP.Layers.Presentations.FormBase;
using STLGROUP.Layers.Common;
using STLGROUP.Layers.DataAccessLayers;

namespace QuanLyBanHang
{
    public partial class frmTaiKhoanNguoiDung : frmCatalogBase
    {
        public frmTaiKhoanNguoiDung()
        {
            InitializeComponent();
        }

        protected override void LoadData()
        {
            this._bindingSource.DataSource = Cache.Context.ACL_TaiKhoan;
            dgvTaiKhoan.DataSource = _bindingSource;

            base.LoadData();
        }

        protected override void AddDataBinding()
        {
            txtMaNhanVien.DataBindings.Add(Const.BIND_TEXT, _bindingSource, "MaNhanVien", true);
            txtHoTen.DataBindings.Add(Const.BIND_TEXT, _bindingSource, "HoTenNhanVien", true);

            cboNhomNguoiDung.DataSource = Cache.Context.ACL_NhomNguoiDung;
            cboNhomNguoiDung.DisplayMember = "TenNhom";
            cboNhomNguoiDung.ValueMember = "IDNhomNguoiDung";
            cboNhomNguoiDung.DataBindings.Add(Const.BIND_SELECTED_VALUE, _bindingSource, "IDNhomNguoiDung", true);

            colNhomNguoiDung.DataSource = Cache.Context.ACL_NhomNguoiDung;
            colNhomNguoiDung.DisplayMember = "TenNhom";
            colNhomNguoiDung.ValueMember = "IDNhomNguoiDung";

            txtTenDangNhap.DataBindings.Add(Const.BIND_TEXT, _bindingSource, "TenDangNhap", true);
            txtMatKhau.DataBindings.Add(Const.BIND_TEXT, _bindingSource, "MatKhau", true);
            txtGoiNho.DataBindings.Add(Const.BIND_TEXT, _bindingSource, "GoiYMatKhau", true);

            base.AddDataBinding();
        }

        private void txtMaNhanVien_KeyDown(object sender, KeyEventArgs e)
        {
            switch (e.KeyData)
            {
                case Keys.Enter:
                    if (!string.IsNullOrWhiteSpace(txtMaNhanVien.Text))
                    {
                        DT_NhanVien nv = Cache.Context.DT_NhanVien.Where(s => s.MaNhanVien == txtMaNhanVien.Text).FirstOrDefault();
                        if (nv != null)
                        {
                            txtHoTen.Text = nv.HoVaTenDem + " " + nv.TenNhanVien;
                        }
                        else
                        {
                            UICommon.ShowMessegeInfo(Const.MSG_KHONG_TIM_THAY_SINH_VIEN);
                        }
                    }
                    break;

            }
        }


    }
}
